//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//

package com.dk.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.dk.entity.TValuationDTO;
import com.dk.entity.TValuationprice;
import com.dk.mapper.TValuationMapper;
import com.dk.mapper.TValuationpriceMapper;
import com.dk.service.ITValuationService;
import java.math.BigDecimal;
import java.util.Date;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class TValuationServiceImpl extends ServiceImpl<TValuationMapper, TValuationDTO> implements ITValuationService {
    @Autowired
    private TValuationMapper tValuationMapper;
    @Autowired
    private TValuationpriceMapper tValuationpriceMapper;


    //线上估值
    public BigDecimal getvaluationPrice(TValuationDTO tValuation, BigDecimal price, Date statedate) {
        //定义上牌时间变量
        int Licensing = 0;
        //计算出当前车辆上牌年数
        Long time = (new Date()).getTime() - statedate.getTime();
        //判断当前年数
        if (time / 1000L / 60L / 60L / 24L / 365L <= 6L) {//小于6年上牌时间改为1
            Licensing = 1;
        } else if (time / 1000L / 60L / 60L / 24L / 365L > 6L && time / 1000L / 60L / 60L / 24L / 365L <= 12L) {//大于6年小于12年上牌时间改为2
            Licensing = 2;
        } else {
            Licensing = 3;;//大于12年上牌时间改为3
        }

        //计算车辆评估基数和
        Integer fractional = tValuation.getDamage() + tValuation.getMileage() + Licensing;
        //根据基数和查询估值百分比表
        QueryWrapper wrapper = new QueryWrapper();
        wrapper.eq("fractional", fractional);
        List<TValuationprice> list = tValuationpriceMapper.selectList(wrapper);
        TValuationprice tValuationprice = (TValuationprice)list.get(0);
        //获取百分比和车辆原价进行计算
        String percentage = tValuationprice.getPercentage();
        BigDecimal bigDecimal = new BigDecimal(percentage);
        BigDecimal bigDecimal1 = new BigDecimal(price.toString());
        BigDecimal v = bigDecimal.multiply(bigDecimal1);
        BigDecimal bigDecimal2 = new BigDecimal(v.toString());
        //得出最终估价
        BigDecimal vprice = bigDecimal1.subtract(bigDecimal2);
        return vprice;
    }
}
